package ru.poomsae.isap

import android.content.Context
import android.content.Intent
import android.net.ConnectivityManager
import android.os.Build
import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import com.example.isap_wtf.Model.ParametrsISAP
import ru.poomsae.isap.Offline.TkdHapkiOffline
import ru.poomsae.isap.Online.TkdHapki
import ru.poomsae.isap.R


class MenuConnectActivity: AppCompatActivity() {

    private lateinit var online: Button
    private lateinit var offline: Button

    @RequiresApi(Build.VERSION_CODES.JELLY_BEAN)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val decorView = window.decorView
        val uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN
        decorView.systemUiVisibility = uiOptions
        getSupportActionBar()?.hide()
        setContentView(R.layout.menu_connect)

        online = findViewById(R.id.online) as Button
        offline = findViewById(R.id.offline) as Button

        online.setOnClickListener {
            ParametrsISAP.onlineConSys = 1
            val intent = Intent (this, TkdHapki::class.java)
            startActivity(intent)
        }

        offline.setOnClickListener {
            val intent = Intent (this, TkdHapkiOffline::class.java)
            startActivity(intent)
        }
    }

    fun isOnline(): Boolean {
        val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        val networkInfo = connectivityManager.activeNetworkInfo
        return networkInfo != null && networkInfo.isConnected
    }

}